package myJs.projectCps.enrichNetworkPlot

import com.softwaremill.quicklens._
import myJs.cps._
import myJs.tool.Tool._

import japgolly.scalajs.react.vdom.all._
import japgolly.scalajs.react._
import japgolly.scalajs.react.React.Fragment
import japgolly.scalajs.react.util.EffectCatsEffect._
import myJs.myPkg.Hooks._
import cats.effect._
import myJs.Implicits._

import scala.collection.immutable.SeqMap

/** Created by yz on 3/11/2020
 */
object LayoutCp {

  val plotO=Cp.plotO

  case class Props(
    basicData: plotO.LayoutData,
    basicDataChange: (plotO.LayoutData => plotO.LayoutData) => SyncIO[Unit]
  ){
    @inline def render: VdomElement = {
      Component(this)
    }
  }

  val Component = ScalaFnComponent[Props] { props =>

    val (varNameStr,setVarNameStr)=useState("")

    object FTool {

      def vChange[T](f: PathLazyModify[plotO.LayoutData, T])(g: String => T) = (v: String) => {
        props.basicDataChange {
          f.setTo(g(v))
        }
      }

      def strChange(f: PathLazyModify[plotO.LayoutData, String]) = FTool.vChange(f)(x=>x)

      def varNameStrChange=(v:String)=>{
        setVarNameStr(v)
      }

    }

    val showSampleMap = SeqMap("T" -> messages("yes"), "F" -> messages("no"))
    val basicData = props.basicData

    Fragment(
      BetweenInlineCp.Props(
        label = messages("picSizeWidthHeight"),
        startName = "width",
        start = basicData.width,
        startChange = FTool.strChange(modifyLens[plotO.LayoutData](_.width)),
        endName = "height",
        end = basicData.height,
        endChange = FTool.strChange(modifyLens[plotO.LayoutData](_.height))
      ).render,
    )


  }

}
